/**
 * @file functions.h
 * @author Benjamin Mayes <bdm8233@rit.edu>
 */
#ifndef FUNCTIONS_H_
#define FUNCTIONS_H_


#include <cstdio>
#include <unistd.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#ifdef _WIN32
#include <conio.h>
#elif defined(__APPLE__) || defined(__linux__)
#include <cstdlib>
#include <cstring>
#include <sys/select.h>
#include <termios.h>
// conio library emulation functions
// I do not take credit for these four functions, all credit goes to
// TODO: Figure out how to credit the guy who wrote these AND test them on Windows/Linux/Solaris platforms.
/**
 * Sets IO flags that allow for asynchronous single character extraction
 * from stdin.
 */
void set_conio_terminal_mode();
/**
 * Resets IO flags to default values.
 */
void reset_terminal_mode();
/**
 * Checks to see if there are characters waiting to be extracted from stdin.
 *
 * @return 1 if there is a character to be extracted, 0 otherwise.
 */
int kbhit();
/**
 * Obtains the oldest unconsumed character from stdin and consumes the character.
 * 
 * @return a single character
 */
int getch();
#endif


/**
 * Facilitates blocking single character input on systems where possible.
 */
unsigned char single_char_input();

template<typename T> 
bool remove_and_delete( T& pointer ) {
    delete pointer;
    return true;
}


template<typename T, typename V>
inline void map_print( const std::pair<T,V>& entry ) {
    std::cout << entry.first << ": " << entry.second << "\n";
}

template<typename T>
inline void linear_print( const T& member ) {
    std::cout << member << "\n";
}

template<typename T>
inline void linear_print_line( const T& member ) {
    std::cout << member << " ";
}
#endif
